import pyperclip
#import pyautogui
import keyboard
import time
import pygetwindow as gw

def get_active_window():
    active_window = gw.getActiveWindow()
    return active_window.title if active_window else None

if __name__ == "__main__":
    stockCodeNum = 0

    print('交易下单软件-模拟粘贴功能已开启')
    while True:
        keyboard.wait('ctrl+v')
        current_app = get_active_window()
        print(f"当前光标所在应用的窗口标题是: {current_app}")
        if '网上股票交易系统5.0' != current_app:
            print('当前光标所在应用的窗口标题 -- 不是 <交易系统>')
            continue
        clipboard_content = pyperclip.paste()
        numbers = ''.join(filter(str.isdigit, clipboard_content))
        for num in numbers:
            time.sleep(0.02)
            keyboard.write(num)
            stockCodeNum = stockCodeNum + 1

            #写完一个计数一次, 写6个计数6次
            if stockCodeNum == 6:
                stockCodeNum = 0;
                break;